package com.lksoft.bz;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JMenuItem;

/**
 * Main function of program (provided by top toolbar buttons and menus)
 * 
 * @author lake
 *
 */
public class Function {
	
	private Action action;
	private String resourceName;
	
	private JButton button;
	private JMenuItem menuItem;

	/**
	 * @param action
	 * @param resourceName
	 */
	public Function(Action action, String resourceName) {
		this.action = action;
		this.resourceName = resourceName;
		
		// Create button and menu
		button = new JButton(action);
		button.setText(null);
		menuItem = new JMenuItem(action);
		menuItem.setIcon(null);
		updateText();
	}

	/**
	 * @return the action
	 */
	public Action getAction() {
		return action;
	}

	/**
	 * @return the resourceName
	 */
	public String getResourceName() {
		return resourceName;
	}

	/**
	 * @return the button
	 */
	public JButton getButton() {
		return button;
	}

	/**
	 * @return the menuItem
	 */
	public JMenuItem getMenuItem() {
		return menuItem;
	}
	
	/**
	 * テキストリソースを現在のLocaleで更新する
	 */
	public void updateText(){
		getButton().setToolTipText(Bz.getUIString(getResourceName()+".tooltip"));
		getMenuItem().setToolTipText(Bz.getUIString(getResourceName()+".tooltip"));
		getMenuItem().setText(Bz.getUIString(getResourceName()+".name"));
	}
}
